package shujujiegou;
import java.util.Scanner;

//定义循环队列类
class abc {
 private int[] queue;  // 用于存储病人病历号的数组
 private int front;    // 队头指针
 private int rear;     // 队尾指针
 private int capacity; // 队列容量

 // 构造函数，初始化队列
 public abc(int size) {
     capacity = size;
     queue = new int[capacity];
     front = 0;
     rear = 0;
 }

 // 判断队列是否已满
 public boolean isFull() {
     return (rear + 1) % capacity == front;
 }

 // 判断队列是否为空
 public boolean isEmpty() {
     return front == rear;
 }

 // 入队操作，将病人病历号加入队列
 public void enqueue(int item) {
     if (isFull()) {
         System.out.println("队列已满，无法加入新病人。");
     } else {
         queue[rear] = item;
         rear = (rear + 1) % capacity;
     }
 }

 // 出队操作，移除并返回队头的病人病历号
 public int dequeue() {
     if (isEmpty()) {
         System.out.println("队列中没有病人。");
         return -1;
     } else {
         int item = queue[front];
         front = (front + 1) % capacity;
         return item;
     }
 }

 // 显示队列中所有病人的病历号
 public void display() {
     if (isEmpty()) {
         System.out.println("没有排队的病人。");
     } else {
         int index = front;
         while (index != rear) {
             System.out.print(queue[index] + " ");
             index = (index + 1) % capacity;
         }
         System.out.println();
     }
 }
}

public class paidui {
 public static void main(String[] args) {
     Scanner scanner = new Scanner(System.in);
     abc queue = new abc(100);  // 创建一个容量为100的队列
     
     System.out.println("**********欢迎使用就诊队列控制系统**********");
     System.out.println("1-排队");
     System.out.println("2-就诊");
     System.out.println("3-查看排队");
     System.out.println("4-不再排队，余下依次就诊");
     System.out.println("5-下班");
     System.out.println("******************************************");

     while (true) {
         System.out.print("1:排队 2：就诊 3：查看排队 4：不再排队，余下依次就诊 5：下班 请选择： ");

         int choice = scanner.nextInt();
         switch (choice) {
             case 1:
                 System.out.print(">>输入病历号:");
                 int medicalRecord = scanner.nextInt();
                 queue.enqueue(medicalRecord);
                 break;
             case 2:
                 int patient = queue.dequeue();
                 if (patient != -1) {
                     System.out.println(">>病人" + patient + "就诊");
                 }
                 break;
             case 3:
                 System.out.print(">>排队病人:");
                 queue.display();
                 break;
             case 4:
                 System.out.print(">>病人按以下顺序就诊:");
                 queue.display();
                 System.exit(0);
             case 5:
                 System.out.println(">>下班了，未就诊的病人明天再来。");
                 System.exit(0);
             default:
                 System.out.println("无效的选项，请重新输入。");
         }
     }
 }
}